package com.xuecheng.content.api;

import com.xuecheng.base.exception.Result;
import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.Teachplan;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description 课程计划编辑接口
 */
 @Api(value = "课程计划编辑接口",tags = "课程计划编辑接口")
 @RestController
public class TeachplanController {
     @Autowired
     private TeachplanService teachplanService;



    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return  teachplanService.findTeachplanTree(courseId) ;
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan( @RequestBody SaveTeachplanDto teachplan){
        teachplanService.saveTeachplan(teachplan);
    }

    /**
     * 删除课程计划
     * @param id
     */
    @ApiOperation("删除课程计划")
    @DeleteMapping("teachplan/{id}")
    public Result deleteTeachplan(@PathVariable Long id){
        Result result = teachplanService.deleteTeachplan(id);
        return result;
    }

    /**
     * 移动课程计划
     * @param moveType
     * @param id
     */
    @ApiOperation("课程计划排序")
    @PostMapping("/teachplan/{moveType}/{id}")
    public void movedown(@PathVariable String moveType,@PathVariable Long id){
        teachplanService.move(moveType,id);
    }
    @ApiOperation("删除课程")
    @DeleteMapping("/course/{courseId}")
    public void deleteCourse(@PathVariable Long courseId){
        Long companyId = 1232141425L;
        teachplanService.deleteCourse(companyId,courseId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){

        teachplanService.associationMedia(bindTeachplanMediaDto);

    }

    @ApiOperation("删除课程计划和媒资信息绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void deletebyteachPlanId(@PathVariable Long teachPlanId,@PathVariable String mediaId)
    {
        teachplanService.deletebyteachPlanId(teachPlanId,mediaId);
    }
    //根据id查询课程计划信息
    @GetMapping("/teachplan/by/{courseId}")
    public List<Teachplan> getBycourseId(@PathVariable ("courseId") Long courseId)
    {
        return teachplanService.getBycourseId(courseId);
    }



}